<?php
namespace app\house\model;
use app\BaseModel;
use think\facade\Db;



class LongPage extends BaseModel
{
    //定义表名
    protected $name = 'longbing_card_house_long_page';



    protected $append = [

        'house_title'
    ];



    public function getImgAttr($value,$data){

        if(!empty($value)){

            return explode(',',$value);
        }

    }


    /**
     * @author chenniang
     * @DataTime: 2021-12-13 14:27
     * @功能说明:获取房源名称
     */
    public function getHouseTitleAttr($value,$data){

        if(!empty($data['house_id'])){

            $house_model = new IndexHouse();

            $title = $house_model->where(['id'=>$data['house_id']])->value('title');

            return $title;

        }


    }
    /**
     * @author chenniang
     * @DataTime: 2021-05-11 16:00
     * @功能说明:添加
     */
    public function dataAdd($data){

        $data['create_time'] = time();

        if(!empty($data['img'])){

            $data['img'] = implode(',',$data['img']);
        }

        $res = $this->insert($data);

        return $res;

    }


    /**
     * @author chenniang
     * @DataTime: 2021-05-11 16:03
     * @功能说明:编辑
     */
    public function dataUpdate($dis,$data){

        if(!empty($data['img'])){

            $data['img'] = implode(',',$data['img']);
        }

        $res = $this->where($dis)->update($data);

        return $res;

    }


    /**
     * @author chenniang
     * @DataTime: 2021-05-11 16:04
     * @功能说明:详情
     */
    public function dataInfo($dis){

        $data = $this->where($dis)->find();

        return !empty($data)?$data->toArray():[];

    }


    /**
     * @author chenniang
     * @DataTime: 2021-05-11 16:05
     * @功能说明:
     */
    public function dataList($dis,$page=10){

        $data = $this->where($dis)->order('top desc,id desc')->paginate($page)->toArray();

        return $data;

    }





}